<?php
namespace app\common\model;

use app\common\model\BaseModel;
use think\Db;
use chrome\ChromePhp;//引入chromephp插件
use common\Common;//公共函数

/**
 * 提供订单快递单号管理服务
 * @name LibExpress.php
 * @package cws
 * @category modle
 * @link http://www.changekeji.com
 * @author yunchen
 * @version 2.0
 * @copyright CHANGE INC
 * @since 2018-02-15
 **/
class LibExpress extends BaseModel{
    private $m_express;

    /**
     * 构造函数
     */
    function __construct() {
        parent::__construct ();
       $this->m_express = db('base_express');
    }
    /**
     * 增加快递公司信息
     * @param array $addInfo
	 * @return array $result
     */
    function addExpress($addInfo){
        try{
            $addId = $this->m_express->insertGetId ( $addInfo );
            if($addId == true){
                return  Common::errorArray(0, "添加成功", $addId);
            }else{
                return  Common::errorArray(1, "添加失败", $addId);
            }
        }catch (Exception $ex){
            $this->errorLog(__CLASS__, __FUNCTION__, $ex);
            return  Common::errorArray(1, "数据库操作失败",$ex);
        }
    }
    
    /**
     * 删除快递公司
     *  @param string $ids
	 *  @return array $result
     */
    function deleteExpress($condition){
       try {
			$reslut = $this->m_express->where($condition)->delete();;		
			if(true == $reslut){
				return Common::errorArray(0, "删除成功",$reslut);
			}else{
				return Common::errorArray(1, "删除失败", $reslut);
			}
		}catch (Exception $ex){
			$this->errorLog(__CLASS__, __FUNCTION__, $ex);
			return  Common::errorArray(1, "数据库操作失败", $ex);
		}
    }
    
    /**
     * 修改快递公司
     *  @param array $expressInfo
     *  @param array $condition
	 *  @return array $result
     */
    function updateExpress( $condition, $expressInfo ){
        try{
            $result = $this->m_express->where($condition)->update($expressInfo );
            if(true == $result){
                return Common::errorArray(0, "修改成功", $result);
            }else{
                return Common::errorArray(1, "修改失败", $result);
            }
        }catch (Exception $ex){
            $this->errorLog(__CLASS__, __FUNCTION__, $ex);
            return  Common::errorArray(1, "数据库操作失败",$ex);
        }
    }
    
    /**
	 * 获取快递信息
	 * @param array $conditions
	 * @return array $result
	 */
	public function findExpress($condition='',$field=''){
		try{
			$result = $this->m_express->where($condition)->field($field)->find();	
			if(true == $result ){
				return Common::errorArray(0, "查找成功", $result);
			}else{
				return Common::errorArray(1, "查找失败", $result);
			}
		}catch (Exception $ex){
		    $this->errorLog(__CLASS__, __FUNCTION__, $ex);
		    return  Common::errorArray(1, "数据库操作失败",$ex);
		}
	}
	
	/**
	 * 获取快递信息
	 * @param array $conditions
	 * @return array $result
	 */
	public function findALLExpress($condition='',$limit='',$field='',$sort=''){
	    try{
	        $result = $this->m_express->where($condition)->order($sort)->limit($limit)->field($field)->select();
	        if(true == $result ){
	            return Common::errorArray(0, "查找成功", $result);
	        }else{
	            return Common::errorArray(1, "查找失败", $result);
	        }
	    }catch (Exception $ex){
	        $this->errorLog(__CLASS__, __FUNCTION__, $ex);
	        return  Common::errorArray(1, "数据库操作失败",$ex);
	    }
	}
    
    /**
     * 分页查询物流信息
     * @param array$page 分页信息
     * @param array $conditionList 条件查询条件
     * @param string $sort 排序字段及方式
     * @return array $result
     */
    public function pagingExpress($page,$conditionList,$sort = '',$orList = null){
       $reslut = Common::paging('base_express',$page,$conditionList,$sort,$orList);
		return  $reslut; 
    }
}
